package org.example.springbootpra1.demos.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.example.springbootpra1.demos.bean.ChargingPile;
import org.example.springbootpra1.demos.bean.myAccount.RechargeRecord;
import org.example.springbootpra1.demos.data.MyAcountMock;
import org.example.springbootpra1.demos.services.service.ChargePileService;
import org.example.springbootpra1.demos.services.service.MyAccountService;
import org.example.springbootpra1.demos.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

/**
 * 充电站Controller
 *
 * @author zdcloud
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/myAccount")
@CrossOrigin(origins = "http://localhost:5173")
public class MyAccountController
{

    @Autowired
    private MyAccountService myAccountService;

    @GetMapping("/balance")
    public Result<String> balance() {
        Random random = new Random();
        int randomBalance = random.nextInt(501); // 生成 0 到 500 之间的随机数
        return Result.Success("余额查询成功", String.valueOf(randomBalance));
    }

//    public String balance()
//    {
//        return "100";
//    }


//    @GetMapping("/recordList")
//    public List<RechargeRecord> balanceList() {
//        List<RechargeRecord> accountList = MyAcountMock.accountList();
//        return accountList;
//    }



    @GetMapping("/recordPage")
    public IPage<RechargeRecord> getRechargeRecords(
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize) {
        return myAccountService.pageList(currentPage, pageSize);
    }
}